<?php

class Application_Model_User extends Core_Model_BaseModel implements Zend_Acl_Role_Interface
{
	
	// Имя таблицы
	protected $_name = 'users';
	private static $_groups = array(
//		 0 => array( 'gr1', 'gr2' ),
//		 1 => array( 'gr2' ),
		 );

//	public function  __construct( $id ) {
//		$this->_name = $id;
//	}

	public function getGroups()
	{
		$return = array();
		if ( !empty ( self::$_groups[$this->getId()] ) )
		{
//			foreach ( self::$_groups[$this->_name] as $groupId ) {
//				$return[] = new Application_Model_Group( $groupId );
//			}
			$return = self::$_groups[$this->getId()];
		}
		return $return;
	}

	public function getRoleId() {
    return 'user-' . $this->_name;
  }


	public static function Auth( $login = '', $password = '', $id = null )
	{
		$return = null;
		$self = new self();
		//$adapter = Zend_Registry::get('db');
		$select = $self->dbAdapter->select();
		if ( $id !== null ) {
			$select->where( "id = ?", $id );  
		} else {
			$select->where( "username = ? and password = ?", $login, $password );  
		}

		 $result = $self->dbAdapter->fetchRow( $select );
		 //$result = $stmt->fetch(Zend_Db::FETCH_OBJ);        
		echo '11'; print_r($result); exit;
		if ( !empty( $result ) ) {
			$return  = new self( $result );
		}

		return $return;
	}
	
	public static function getInstance( $id )
	{
		return self::Auth( '', '', $id );
	}

}

